/* ========================================================================== */
/*   ReadLogHandler.cpp    		                                              */
/*   (c) 2012 Team 7 Hogeschool Utrecht ICT TI                                */
/*		Lars Stolwijk, Gerben Boot, Guido van Hienen, Marcel Boelen			  */
/*                                                                            */
/* 	 Communicates with the log and receives signals from the IRSensor. Sends  */
/*		the data from the Log to the ReadLogController for further process.   */
/* ========================================================================== */
#include "ReadLogHandler.h"

void ReadLogHandler::RegisterLog(Log * log){
	theLog = log;
}

void ReadLogHandler::main()
{
	for(;;){
		RTOS::event e = wait( ReadLogFlag );
		std::cout << "RLH::main() 1/5\n";
		theSoundController->PlayReadLogSound();
		std::cout << "RLH::main() 2/5\n";
		theLog->GetLog();
		std::cout << "RLH::main() 3/5\n";
		LogFile *file = LogMailbox.read();
		std::cout << "RLH::main() 4/5\n";
		readLogController->SendLog(file);
		std::cout << "RLH::main() 5/5\n";
		//delete [] file;
	}
}

void ReadLogHandler::ReadLog()
{
	std::cout << "RLH::ReadLog() 1/2\n";
	ReadLogFlag.set();	
	std::cout << "RLH::ReadLog() 2/2\n";
}

void ReadLogHandler::WriteLog(LogLine arr[])
{
	std::cout << "RLH::WriteLog() 1/2\n";
	file.array = arr;
	LogMailbox.write(&file);
	std::cout << "RLH::WriteLog() 2/2\n";
}
